//
//  WFMainTBC.swift
//  WangFangWeiBo
//
//  Created by 王方 on 16/7/9.
//  Copyright © 2016年 wf. All rights reserved.
//

import UIKit
import SVProgressHUD
class WFMainTBC: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //用kvc给只读属性赋值,将系统的替换成我们自己定义的
        let tabbar = WFTabbar()
        
        tabbar.composeBtnClosure = {()->() in
            print("在控制器中获取到了composebtn被点击了")
            
            if !WFUserAccountViewModel.sharedUserAccount.isLogin{
                SVProgressHUD.showErrorWithStatus("请先登录呀~")
                return
            }
            //  代码执行到此表示已经登录
            
            let composeView = WFComposeView()
            //  获取最上面的一个window
//            let window = UIApplication.sharedApplication().windows.last!
//            
//            window.addSubview(composeView)
            composeView.show(self)
            
            
        }
       setValue(tabbar, forKey: "tabBar")
       
        
        
        addChildViewController(WFHomeTVC(), title: "首页", imageName: "tabbar_home")
         addChildViewController(WFMessageTVC(), title: "消息", imageName: "tabbar_message_center")
         addChildViewController(WFDiscoverTVC(), title: "发现", imageName: "tabbar_discover")
         addChildViewController(WFProfileTVC(), title: "我的", imageName: "tabbar_profile")
        
    }

    /**
     添加子控制器
     
     - parameter childController: 控制器
     - parameter title:           控制器名字
     - parameter imageName:       控制器的图片
     */
    func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        //用自己定义的tabbaritem进行替换
        childController.tabBarItem = WFTabBarItem()
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName+"_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        //设置字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        //设置字体大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: .Normal)
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)

        
    }

}
